<template>
  <el-table :data="filterTableData" style="width: 100%">
    <el-table-column label="Name" prop="name" />
    <el-table-column label="Class" prop="class" />
    <el-table-column label="Num" prop="num" />

    <el-table-column align="right">
      <template #header>
        <el-input v-model="search" size="small" placeholder="Type to search" />
      </template>
      <template #default="scope">
        <el-tag
            v-for="item in items"
            :key="item.label"
            :type="item.type"
            effect="dark"
            style="margin-left: 2px"
        >
          {{ item.label }}
        </el-tag>
      </template>
    </el-table-column>
  </el-table>
</template>

<script lang="ts" setup>
import { computed, ref } from 'vue'
const items = ref<Array<Item>>([
  { type: 'success', label: '已完成1' },
  { type: 'warning', label: '进行中2' },
  { type: 'danger', label: '未完成3' },
])
interface User {
  class: string
  name: string
  num: string
}

const search = ref('')
const filterTableData = computed(() =>
    tableData.filter(
        (data) =>
            !search.value ||
            data.name.toLowerCase().includes(search.value.toLowerCase())
    )
)
const tableData: User[] = [
  {
    class:'22软件1班',
    name: 'Tom',
    num: '123456',
  },
  {
    class:'22软件1班',
    name: 'John',
    num: '123456',
  },
  {
    class:'22软件1班',
    name: 'Morgan',
    num: '123456',
  },
  {
    class:'22软件1班',
    name: 'Jessy',
    num: '123456',
  },
]
</script>
